<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script type="text/javascript">
        function Person(name, age, gender) {
            this.name = name;
            this.age = age;
            this.gender = gender;
            //向对象中添加一个方法
            this.sayName = fun;
        }

        //将sayName方法在全局作用域中定义
        /*
         * 将函数定义在全局作用域，污染了全局作用域的命名空间
         *  而且定义在全局作用域中也很不安全
         */
        /*
        var name = "jkh";
        var name = "jkh222";
        var age = "jkh";
        var gender = "jkh";
        Person(name, age, gender)
        fun()

        function fun() {
            alert("Hello大家好，我是:" + this.name);
        };
        */
        var name = "jkh";
        var name = "jkh222";
        var age = "jkh";
        var gender = "jkh";
        Person(name, age, gender)


        Person.prototype.sayName = function() {
            alert("Hello大家好，我是：" + this.name);
        };
    </script>
</body>

</html>